# include <cstdio>
# include <cstring>
# include <iostream>
# include <algorithm>
using namespace std;

# define testin freopen("in.txt", "r", stdin)
# define testout freopen("out.txt", "w", stdout)

# define rep(x) for(int i = 0; i < (x); ++i)
# define clr(x) memset(x, 0, sizeof(x))
# define clrc(x, c) memset(x, 0, (c)*sizeof(x[0]))

typedef unsigned long long int ulli;
typedef long long int lli;

int n;
int a[1005];
int f[1005][1005];
int dp(int i, int j)
{
    if (f[i][j]!=-1) return f[i][j];
    if (i>=j) return f[i][j] = 0;
    f[i][j] = dp(i+1, j);
    for (int k = i+1; k <= j; ++k) {
        f[i][j] = max(f[i][j],  (a[k]-a[i])*(a[k]-a[i])+dp(k+1, j) );
    }
    return f[i][j];
}
int main()
{
    while (cin >> n) {
        rep(n) cin >> a[i];
        memset(f, -1, sizeof(f));
        cout << dp(0, n-1) << endl;
    }
    return 0;
}

